﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace KELT.ErrorControl
{
    public sealed class ErrorManager
    {
        private static ErrorManager instance;
        private static object syncRoot = new Object();
        private static String defaultErrorFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\KELT\\Error";

        private ErrorManager()
        {
            CreateDefaultErrorFolder();
        }

        public static ErrorManager Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new ErrorManager();
                        }
                    }
                }

                return instance;
            }
        }

        public void CreateDefaultErrorFolder()
        {
            DirectoryInfo dirInfo = new DirectoryInfo(defaultErrorFolder);

            try
            {
                if (!dirInfo.Exists)
                {
                    dirInfo.Create();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error In Error Manager");
                Console.WriteLine("createDefaultErrorFolder()");
                Console.WriteLine("Error Message : {0}", e.Message);
            }
        }

        public void RecordError(Exception e)
        {
            //Console.WriteLine(e.ToString());
            Console.WriteLine("Error Message : " + e.Message);
            Console.WriteLine("Stack Trace : " + e.StackTrace);
        }
    }
}
